package com.example.fina2202.day09;

import java.util.Arrays;

public class InsertionSort {
    public static void main(String[] args) {
        int[] ary={98,87,0,43,65,54,32,21,10,8,7};

        //对未排序部分遍历
        for (int i=1;i<ary.length;i++){
            //跟踪插入元素的实时下标
            for (int j=i;j>0 && ary[j]<ary[j-1];j--){
                int tmp = ary[j];
                ary[j] = ary[j-1];
                ary[j-1] = tmp;
            }
        }
        System.out.println(Arrays.toString(ary));
    }
}
